package ch14;

import java.util.Date;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;

public class Aimbot extends Application {
    public static void main(String[] args) {
        launch(args);
    }

    Date start;
    int n = 0;

    @Override
    public void start(Stage primaryStage) throws Exception {
        Pane mainpane = new Pane();
        Circle circle = new Circle(20);
        circle.setFill(Color.BLACK);
        mainpane.getChildren().add(circle);
        Scene scene = new Scene(mainpane, 300, 300);
        primaryStage.setScene(scene);
        primaryStage.setMaximized(true);
        primaryStage.show();
        circle.setCenterX(scene.getWidth() / 2);
        circle.setCenterY(scene.getHeight() / 2);
        circle.setOnMousePressed(e -> {
            if (n == 0)
                start = new Date();
            n++;
            if (n == 20) {
                mainpane.getChildren().clear();
                Label time = new Label("用时" + (new Date().getTime() - start.getTime()) / 1000.0 + "秒");
                mainpane.getChildren().add(time);
            } else {
                circle.setCenterX(Math.random() * (scene.getWidth() - 40) + 20);
                circle.setCenterY(Math.random() * (scene.getHeight() - 40) + 20);
            }
        });
    }
}